//
//  ClassManageCell.m
//  IpadTestB
//
//  Created by edianzu on 2017/7/3.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ClassManageCell.h"

@implementation ClassManageCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
    }
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}


-(void)creatUI{
    self.className = [[UILabel alloc]init];
    self.className.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
    self.className.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.className];
    [self.className mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(50*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(450*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    self.deleteClassBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.deleteClassBtn addTarget:self action:@selector(callDeleteT) forControlEvents:UIControlEventTouchUpInside];
    [self.deleteClassBtn setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteClassBtn setTitleColor:UIColorFromRGB(26, 167, 157) forState:UIControlStateNormal];
    self.deleteClassBtn.titleLabel.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
    [self.contentView addSubview:self.deleteClassBtn];
    [self.deleteClassBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView. mas_right).with.offset(-50*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60*AutoScaleHorizontal, 40*AutoScaleVertical));
    }];
    
    
    self.changeNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.changeNameBtn addTarget:self action:@selector(callChangeT) forControlEvents:UIControlEventTouchUpInside];
    [self.changeNameBtn setTitle:@"修改名称" forState:UIControlStateNormal];
    [self.changeNameBtn setTitleColor:UIColorFromRGB(26, 167, 157) forState:UIControlStateNormal];
    self.changeNameBtn.titleLabel.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
    [self.contentView addSubview:self.changeNameBtn];
    [self.changeNameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.deleteClassBtn.mas_left).with.offset(-30*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(90*AutoScaleHorizontal, 40*AutoScaleVertical));
    }];
    
    UIView * bottomView = [[UIView alloc]init];
    bottomView.backgroundColor = UIColorFromRGB(241, 244, 248);
    [self.contentView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.left.right.mas_equalTo(self.contentView);
        make.height.mas_equalTo(10*AutoScaleVertical);
    }];
}




-(void)relayoutCellWithModel:(ClassModel *)model andIndex:(NSIndexPath *)indexpath{
    self.changeNameBtn.hidden =NO;
    self.deleteClassBtn.hidden = NO;
    self.indexPath = indexpath;
    NSLog(@"%@",self.indexPath);
    self.className.text = model.Name;
    if ([model.Name isEqualToString:@"未分班"]) {
        self.changeNameBtn.hidden =YES;
        self.deleteClassBtn.hidden = YES;
    }
}

-(void)callDeleteT{
    self.callDelete(self.indexPath);
    NSLog(@"%@",self.indexPath);
}
-(void)callChangeT{
    self.callChange(self.indexPath);
    NSLog(@"%@",self.indexPath);
}
@end



























